const app = getApp();

let common=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.serverUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let nb=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.nbUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let equipment=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.equipmentUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){  
        reject();
      }
    })
  });
}

let equipment2=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({      
      url: app.globalData.equipmentUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let authority=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.authorityUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let authority2=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({      
      url: app.globalData.authorityUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let wechat=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.wechatUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//用于验证码登录
let wechat2=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({
      url: app.globalData.wechatUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let report=function(url,data){
  return new Promise((resolve,reject)=>{    
    wx.request({ 
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },    
      url: app.globalData.reportUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let go=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let goNb=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goNb + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//用友接口
let yy=function(url,data){
    return new Promise((resolve,reject)=>{
      wx.request({
        header: {
          'Content-Type': "application/json;charset=UTF-8",
          'Authorization': 'Bearer ' + app.globalData.loginToken,
        },
        url:app.globalData.yy + url,
        method: "POST",
        data: data,
        success(res) {
          resolve(res);
        },
        fail(){
          reject();
        }
      })
    });
}

//同步pcsql数据库
let syncPgSql=function(url,data){
    return new Promise((resolve,reject)=>{
      wx.request({
        header: {
          'Content-Type': "application/json;charset=UTF-8",
          'Authorization': 'Bearer ' + app.globalData.loginToken,
        },
        url:app.globalData.syncPgSql + url,
        method: "POST",
        data: data,
        success(res) {
          resolve(res);
        },
        fail(){
          reject();
        }
      })
    });
}

module.exports = {
  common:common,
  nb:nb,
  equipment:equipment,
  equipment2:equipment2,
  authority:authority,
  wechat:wechat,
  wechat2:wechat2,
  authority2:authority2,
  report:report,
  go:go,
  goNb:goNb,
  yy:yy,
  syncPgSql: syncPgSql
}